package com.googlecode.FWT.controller
{

	import com.googlecode.FWT.view.pages.activity.PrintTextArea;
	
	import mx.core.ScrollPolicy;
	import mx.printing.FlexPrintJob;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;

	public class PrintCommand extends SimpleCommand
	{
		override public function execute(notification:INotification):void
		{

			// create an instance of the FlexPrintJob class
            var printJob:FlexPrintJob = new FlexPrintJob();
            
            // get the html string from the notification body
            var fw:PrintTextArea = notification.getBody() as PrintTextArea;
            
            //Start the print job.
            if(printJob.start() != true)
            {
            	return;
            }
             
            printJob.printAsBitmap = false;
            
            // this sets the freewrite area page to the same height and width as the printed page 
            fw.printWidth = printJob.pageWidth;
            fw.printHeight = printJob.pageHeight;
                   
            // ensures the page is set up correctly for printing
            fw.setPageforPrinting();
            
            printJob.addObject(fw);
            
           	printJob.send();
           	
            fw.reset();
		}
		
	}
}